package com.ffws.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ffws.base.model.RestResponse;
import com.ffws.content.mapper.*;
import com.ffws.content.model.po.*;
import com.ffws.content.service.MainContentService;
import com.ffws.feign.po.Person;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author JC
 * @description TODO
 * @Date 2023-8-29 18:55
 * @Version 1.0
 */
@Service
@Slf4j
public class MainContentServiceImpl implements MainContentService {

    @Resource
    MainTabMapper mainTabMapper;

    @Resource
    PersonMapper personMapper;

    @Resource
    AllocatedMapper allocatedMapper;

    @Resource
    FireInformationMapper fireInformationMapper;

    @Resource
    NewConditionMapper newConditionMapper;

    @Override
    public RestResponse<List<MainTab>> getMainTab() {
        List<MainTab> list = mainTabMapper.selectList(new LambdaUpdateWrapper<>());
        return RestResponse.success(list);
    }

    @Override
    public RestResponse<List<Person>> getPersonList(Long tabId) {
        Allocated allocated = allocatedMapper.selectOne(new LambdaUpdateWrapper<Allocated>()
                .eq(Allocated::getTabId,tabId));
        if (allocated == null) {
            return RestResponse.validfail("该标签对应的成员无数据");
        }
        List<Long> personIdList = allocated.getPersonId();
        List<Person> personList = new ArrayList<>();
        personIdList.forEach(personId->{
            personList.add(personMapper.selectById(personId));
        });
        return RestResponse.success(personList);
    }

    @Override
    public RestResponse<FireInformation> getFireInfo(Long tabId) {
        FireInformation fireInformation = fireInformationMapper.selectOne(new LambdaUpdateWrapper<FireInformation>()
                .eq(FireInformation::getTabId, tabId));
        return RestResponse.success(fireInformation);
    }

    @Override
    public RestResponse<NewCondition> getNewCondition(Long tabId) {
        NewCondition newCondition = newConditionMapper.selectOne(new LambdaUpdateWrapper<NewCondition>()
                .eq(NewCondition::getTabId, tabId));
        return RestResponse.success(newCondition);
    }

    @Override
    public Person getPersonById(Long id) {
        return personMapper.selectById(id);
    }

}
